<template>
  <div>
    <el-row type="flex">
      <el-form-item label="城市" label-width="70px" style="font-weight: 700">
        <el-select
          size="small"
          v-model.trim="form.province"
          placeholder="请选择"
          @change="changeFn"
        >
          <el-option
            v-for="(item, index) in provincesList"
            :key="index"
            :label="item"
            :value="item"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="地区" label-width="70px" style="font-weight: 700">
        <el-select size="small" v-model="form.city" placeholder="请选择">
          <el-option
            v-for="(item, index) in citysList"
            :key="index"
            :label="item"
            :value="item"
          ></el-option>
        </el-select>
      </el-form-item>
    </el-row>
  </div>
</template>

<script>
// 引入 城市
import { provinces, citys } from "@/api/constant/city";
export default {
  name: "City",
  data() {
    return {
      // form表单数据
      provincesList: provinces(), // 城市
      citysList: [], // 地区
      form: {
        province: "", // 城市
        city: "", // 地区
      },
    };
  },
  methods: {
    // 选择城市的方法
    changeFn() {
      // 获取地区赋值给本地
      this.citysList = citys(this.form.province);
    },
  },
};
</script>

<style scoped lang="less"></style>
